//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#ifndef _SERIAL_DEFINE_H_
#define _SERIAL_DEFINE_H_

#include <elatypes.h>
#include <ddk.h>

/////////////////////////////////////////////////////////////

/* TYPE DEFINITIONS */

//typedef signed char     INT8;
//typedef unsigned char   UINT8;
//typedef signed int      INT32;
//typedef unsigned int    UINT32;

// -------------------------------------------------------------------------
// The obvious few that compilers may define for you.
// But in case they don't:

#ifndef NULL
# define NULL 0
#endif

#ifndef __cplusplus

#ifndef false
#define false 0
#endif

#ifndef true
#define true (!false)
#endif

#endif

typedef _ELASTOS UInt32  SERIAL_ADDRWORD, SERIAL_UCOUNT32;
typedef _ELASTOS UInt32  SERIAL_WORD;

typedef  bool            boolean;

/* A type for error codes which may be useful to explain the purpose of
 * a variable or return code. It shows that it contains an error code
 * of the type defined below */

typedef int SERIAL_ErrNo;

#define ENOERR 0

typedef DzEvent                             drv_event_t;
typedef DzMutex                             drv_mutex_t;

typedef void * io_handle_t;

///////////////////////////////////////////////////
#define _mutex_init(p)
#define _drv_mutex_lock(p, wr)              (p)->Lock(wr)
#define _drv_mutex_unlock(p)                (p)->Unlock()

#define _drv_event_init(p)

#define _drv_event_wait(p, wr)              (p)->Wait(wr, NULL)

#define _drv_event_try_wait(p, wr, timeout) (p)->TryWait(timeout, wr, NULL)

#define _drv_event_notify_by_isr(p)         (p)->NotifyByIsr();
#define _drv_event_notify(p)                (p)->Notify();

#define _drv_event_clear(p)                 (p)->Clear();

//////////////////////////////////////////////////

// macros

#define HAL_WRITE_UINT8(_register_, _value_)  \
            Outb((_register_), (_value_))

#define HAL_READ_UINT8(_register_, _value_)  \
            ((_value_) = Inb((_register_)))

#define HAL_WRITE_UINT32(_register_, _value_)  \
            Outl((_register_), (_value_))

#define HAL_READ_UINT32(_register_, _value_)  \
            ((_value_) = Inl((_register_)))

#define dbgPrint  kprintf

#define SERIAL_ASSERT(err, msg) assert(err && msg)
#define SERIAL_FAIL(msg)        assert(0 && msg)

// compile option
#define __inline__ inline

#define SERIALDBG_IO_INIT // display a debug message

#define SERIALNUM_IO_SERIAL_FLOW_CONTROL_LOW_WATER_PERCENT     33
#define SERIALNUM_IO_SERIAL_FLOW_CONTROL_HIGH_WATER_PERCENT    66

#if 0
#define SERIAL_LOG1(x)                           kprintf(x)
#define SERIAL_LOG2(x1, x2)                      kprintf(x1, x2)
#define SERIAL_LOG3(x1, x2, x3)                  kprintf(x1, x2, x3)
#define SERIAL_LOG4(x1, x2, x3, x4)              kprintf(x1, x2, x3, x4)
#define SERIAL_LOG5(x1, x2, x3, x4, x5)          kprintf(x1, x2, x3, x4, x5)
#else
#define SERIAL_LOG1(x)
#define SERIAL_LOG2(x1, x2)
#define SERIAL_LOG3(x1, x2, x3)
#define SERIAL_LOG4(x1, x2, x3, x4)
#define SERIAL_LOG5(x1, x2, x3, x4, x5)
#endif /* _DEBUG */

#endif // _SERIAL_DEFINE_H_
